//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "G2Process.h"
using namespace Cephei::QL::Processes;
#include <gen/QL/Math/Array.h>
#include <gen/QL/StochasticProcess.h>
using namespace Cephei::QL::Math;
using namespace Cephei::QL;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Processes::CG2Process::CG2Process (Double a, Double sigma, Double b, Double eta, Double rho) : CStochasticProcess(CG2Process::typeid)
{
    try
    {
#ifdef HANDLE
        _phG2Process = NULL;
#endif
        QuantLib::Real _a = (QuantLib::Real)ValueHelper::Convert (a);
        QuantLib::Real _sigma = (QuantLib::Real)ValueHelper::Convert (sigma);
        QuantLib::Real _b = (QuantLib::Real)ValueHelper::Convert (b);
        QuantLib::Real _eta = (QuantLib::Real)ValueHelper::Convert (eta);
        QuantLib::Real _rho = (QuantLib::Real)ValueHelper::Convert (rho);
        _ppG2Process = new boost::shared_ptr<QuantLib::G2Process> (new QuantLib::G2Process ( _a,  _sigma,  _b,  _eta,  _rho ));
        SetStochasticProcess (boost::dynamic_pointer_cast<QuantLib::StochasticProcess> (*_ppG2Process));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Processes::CG2Process::CG2Process (boost::shared_ptr<QuantLib::G2Process>& childNative, Object^ owner) : CStochasticProcess(CG2Process::typeid)
{
#ifdef HANDLE
	_phG2Process = NULL;
#endif
	_ppG2Process = &childNative;
    _ppStochasticProcess = new boost::shared_ptr<QuantLib::StochasticProcess> (boost::dynamic_pointer_cast<QuantLib::StochasticProcess> (*_ppG2Process));
}
Cephei::QL::Processes::CG2Process::CG2Process (QuantLib::G2Process& childNative, Object^ owner) : CStochasticProcess(CG2Process::typeid)
{
#ifdef HANDLE
	_phG2Process = NULL;
#endif
	_ppG2Process = new boost::shared_ptr<QuantLib::G2Process> (&childNative);
    _ppStochasticProcess = new boost::shared_ptr<QuantLib::StochasticProcess> (boost::dynamic_pointer_cast<QuantLib::StochasticProcess> (*_ppG2Process));
    _G2ProcessOwner = owner;
    _StochasticProcessOwner = owner;
}

Cephei::QL::Processes::CG2Process::CG2Process (CG2Process^ copy) : CStochasticProcess(CG2Process::typeid)
{
#ifdef HANDLE
	_phG2Process = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppG2Process = new boost::shared_ptr<QuantLib::G2Process> (copy->GetShared());
        _ppStochasticProcess = new boost::shared_ptr<QuantLib::StochasticProcess> (boost::dynamic_pointer_cast<QuantLib::StochasticProcess> (*_ppG2Process));
    }
}
Cephei::QL::Processes::CG2Process::CG2Process (System::Type^ t) : CStochasticProcess(CG2Process::typeid)
{
#ifdef HANDLE
	_phG2Process = NULL;
#endif
	if (!t->IsSubclassOf(CG2Process::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Processes::CG2Process::CG2Process (QuantLib::Handle<QuantLib::G2Process>& childNative, Object^ owner)  : CStochasticProcess(CG2Process::typeid)
{
	_phG2Process = &childNative;
	_ppG2Process = &static_cast<boost::shared_ptr<QuantLib::G2Process>>(childNative.currentLink());
    _ppStochasticProcess = new boost::shared_ptr<QuantLib::StochasticProcess> (boost::dynamic_pointer_cast<QuantLib::StochasticProcess> (*_ppG2Process));
    _G2ProcessOwner = owner;
}
Cephei::QL::Processes::CG2Process::CG2Process (QuantLib::Handle<QuantLib::G2Process> childNative)  : CStochasticProcess(CG2Process::typeid)
{
	_phG2Process = &childNative;
	_ppG2Process = &static_cast<boost::shared_ptr<QuantLib::G2Process>>(childNative.currentLink());
    _ppStochasticProcess = new boost::shared_ptr<QuantLib::StochasticProcess> (boost::dynamic_pointer_cast<QuantLib::StochasticProcess> (*_ppG2Process));
}
#endif
#ifdef STRUCT
Cephei::QL::Processes::CG2Process::CG2Process (QuantLib::G2Process childNative)  : CStochasticProcess(CG2Process::typeid)
{
#ifdef HANDLE
	_phG2Process = NULL;
#endif
	_ppG2Process = new boost::shared_ptr<QuantLib::G2Process> (new QuantLib::G2Process (childNative));
    _ppStochasticProcess = new boost::shared_ptr<QuantLib::StochasticProcess> (boost::dynamic_pointer_cast<QuantLib::StochasticProcess> (*_ppG2Process));
}
#endif

Cephei::QL::Processes::CG2Process::~CG2Process ()
{
    if (_ppG2Process != NULL)
    {
	    delete _ppG2Process;
        _ppG2Process = NULL;
    }
}
Cephei::QL::Processes::CG2Process::!CG2Process ()
{
    if (_ppG2Process != NULL)
    {
	    delete _ppG2Process;
    }
}
QuantLib::G2Process& Cephei::QL::Processes::CG2Process::GetReference ()
{
    if (_ppG2Process == NULL) throw gcnew NativeNullException ();
	return **_ppG2Process;
}
boost::shared_ptr<QuantLib::G2Process>& Cephei::QL::Processes::CG2Process::GetShared ()
{
    if (_ppG2Process == NULL) throw gcnew NativeNullException ();
	return *_ppG2Process;
}
QuantLib::G2Process* Cephei::QL::Processes::CG2Process::GetPointer ()
{
    if (_ppG2Process == NULL) throw gcnew NativeNullException ();
	return &**_ppG2Process;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::G2Process>& Cephei::QL::Processes::CG2Process::GetHandle ()
{
	if (_phG2Process == NULL)
	{
		_phG2Process = new Handle<QuantLib::G2Process> (*_ppG2Process);
	}
	return *_phG2Process;
}
#endif
bool Cephei::QL::Processes::CG2Process::HasNative () 
{
	return (_ppG2Process != NULL);
}

Double Cephei::QL::Processes::CG2Process::A::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppG2Process)->a ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Processes::CG2Process::B::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppG2Process)->b ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Processes::CG2Process::Eta::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppG2Process)->eta ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Processes::CG2Process::Rho::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppG2Process)->rho ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Processes::CG2Process::Sigma::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppG2Process)->sigma ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
UInt64 Cephei::QL::Processes::CG2Process::Size::get ()
{
    try
    {
    	QuantLib::Size _rv = (QuantLib::Size)(*_ppG2Process)->size ( );   
        UInt64 _nrv = (UInt64)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Processes::CG2Process::X0::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppG2Process)->x0 ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Processes::CG2Process::Y0::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppG2Process)->y0 ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Processes::IG2Process^ Cephei::QL::Processes::CG2Process_Factory::Create (Double a, Double sigma, Double b, Double eta, Double rho)
{
    return gcnew CG2Process ( a,  sigma,  b,  eta,  rho);
}
